﻿using GrapeCity.Forguncy.CellTypes;
using GrapeCity.Forguncy.Commands;
using GrapeCity.Forguncy.Plugin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Windows;
using Vant.Properties;
using Vant.WpfControls;
using Vant.WpfControls.DrawingObject;

namespace Vant.CellTypes
{
    public class ProgressDesigner : CellTypeDesigner<Progress>
    {
        public override FrameworkElement GetDrawingControl(ICellInfo cellInfo, IDrawingHelper drawingHelper)
        {
            var cellStyleViewModel = StyleHelper.CreateStyleViewModel(cellInfo, drawingHelper);
            return new ProgressDrawingObject(this.CellType, cellStyleViewModel, cellInfo, drawingHelper);
        }
    }

    [Designer("Vant.CellTypes.ProgressDesigner, Vant")]
    [Icon("pack://application:,,,/Vant;component/Resources/Images/Progress.png")]
    [OrderWeight((int)Utils.OrderWeight.Progress)]
    public class Progress : VantCellTypeBase, ICommandCellType, ISupportDefaultValue
    {
        [SRDisplayName(nameof(Resources.ValueChangeCommand))]
        public List<Command> CommandList { get; set; } = new List<Command>();

        public CommandExcuteKind CommandExcuteKind => CommandExcuteKind.OnValueChanged;

        [SRDisplayName(nameof(Resources.Vant_DefaultValue))]
        [FormulaProperty]
        public object DefaultValue { get; set; }

        [Browsable(false)]
        [JsonIgnore]
        public bool NeedFormatDefaultValue { get; set; } = true;

        [SRDisplayName(nameof(Resources.Progress_StrokeWidth))]
        [DefaultValue(4)]
        public int strokeWidth { get; set; } = 4;

        [SRDisplayName(nameof(Resources.Progress_Color))]
        [ColorProperty]
        public string color { get; set; } = "Accent 1";

        [SRDisplayName(nameof(Resources.Progress_LayerColor))]
        [ColorProperty]
        public string trackColor { get; set; } = "#e5e5e5";

        [SRDisplayName(nameof(Resources.Progress_ShowPivot))]
        [BoolProperty]
        [DefaultValue(true)]
        public bool showPivot { get; set; } = true;

        [SRDisplayName(nameof(Resources.Progress_Text))]
        [FormulaProperty]
        public object pivotText { get; set; }

        [SRDisplayName(nameof(Resources.Progress_PivotColor))]
        [ColorProperty]
        public string pivotColor { get; set; } = "Accent 1";

        public override bool GetDesignerPropertyVisible(string propertyName)
        {
            if (propertyName == nameof(pivotText) ||
                propertyName == nameof(pivotColor)
                )
            {
                return showPivot;
            }
            return base.GetDesignerPropertyVisible(propertyName);
        }

        [SRDisplayName(nameof(Resources.Progress_ChangeProgressStatus))]
        [RunTimeMethod]
        public void ChangeProgressStatus(
            [SRItemDisplayName(nameof(Resources.Progress_PivotText))]
            string pivotText,

            [SRItemDisplayName(nameof(Resources.Progress_PivotColor))]
            [ColorProperty(SupportNoFill = true)]
            string pivotColor,

            [SRItemDisplayName(nameof(Resources.Progress_TextColor))]
            [ColorProperty(SupportNoFill = true)]
            string textColor,

            [SRItemDisplayName(nameof(Resources.Progress_Color))]
            [ColorProperty(SupportNoFill = true)]
            string color)
        {
            //
        }

        public override string ToString()
        {
            return Properties.Resources.Progress;
        }
    }
}
